﻿using Nop.Core.Domain.Logistics;
using System.Data.Entity.ModelConfiguration;

namespace Nop.Data.Mapping.Logistics
{
    public class ZoneMap : EntityTypeConfiguration<Zone>
    {
        public ZoneMap()
        {
            this.ToTable("LogisticsZone");
            this.HasKey(z => z.Id);

            this.Property(z => z.Name)
                .IsRequired()
                .HasMaxLength(1000);

            this.Property(z => z.ZipPostalCode)
                .IsRequired()
                .HasMaxLength(1000);

            this.HasRequired(z => z.District)
                .WithMany(d => d.Zones)
                .HasForeignKey(z => z.DistrictId);

            this.HasOptional(z => z.ZoneGroup)
                .WithMany(zg => zg.Zones)
                .HasForeignKey(z => z.ZoneGroupId)
                .WillCascadeOnDelete(false);
        }
    }
}
